package com.aopeng.controller;

import com.aopeng.entity.AopengExamination;
import com.aopeng.mapper.AopengExaminationMapper;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * zqh
 * 对试卷操作
 */
@Controller
public class AopengExaminationController {
    @Autowired
    private AopengExaminationMapper aopengExaminationMapper;

    //获取所有的数据
    @RequestMapping("/getAopengExamination")
    public  String getAopengExamination(Model model){
        System.out.println("查询全部");
        List<AopengExamination> getAopengExamination = aopengExaminationMapper.selectList(null);
        model.addAttribute("getAopengExamination",getAopengExamination);
        return "/admin/tablest";
    }

    //根据id获取数据
    @RequestMapping("/getAopengExaminationById")
    public void getAopengExaminationById(){
        System.out.println("根据id查询");
        //获取前台传过来的数据
        int index = 1;
        AopengExamination aopengExamination = aopengExaminationMapper.selectById(index);
        System.out.println(aopengExamination);
    }

    //根据id修改数据
    @RequestMapping("/updateAopengExaminationById")
    public void updateAopengExaminationById(){
        System.out.println("根据id修改数据");
        //获取前台传过来的数据
        int index = 1;
        AopengExamination aopengExamination = new AopengExamination();
        int i = aopengExaminationMapper.updateById(aopengExamination);
        System.out.println(i);
    }

    //增加数据
    @RequestMapping("/insertAopengExaminationById")
    public void insertAopengExaminationById(){
        System.out.println("增加数据");
        AopengExamination aopengExamination = new AopengExamination();
        int i = aopengExaminationMapper.insert(aopengExamination);
        System.out.println(i);
    }

    //根据id删除
    @RequestMapping("/deleteAopengExaminationById")
    public String deleteAopengExaminationById(long id){
        System.out.println("根据id删除数据"+id);
        aopengExaminationMapper.deleteById(id);
        return "redirect:/getAopengExamination";
    }
}
